import java.util.*;

class Node {
    int data;
    Node next;

    public Node(int data, Node next) {
        this.data = data;
        this.next = next;
    }
}

public class SigForHeadList {
    static public Scanner sc = new Scanner(System.in);

    static public void p(String format, Object ... obj) {
        System.out.printf(format, obj);
    }

    static public void main(String [] args) {
        int num;
        Node head = new Node(0, null), newNode = null, tail = null;

        head.next = head;

        while (true) {
            p("请输入数字(-1为退出): ");
            num = sc.nextInt();

            if (num == -1)
                break;

            newNode = new Node(num, head);
            tail = head;
            while (tail.next != head) {
                tail = tail.next;
            }
            // System.out.printf("tail.data = %d\n", tail.data);
            tail.next = newNode;
        }

        for (tail = head.next; tail != head; tail = tail.next) {
            System.out.printf("%d ", tail.data);
        }
        System.out.println();

    }
}
